# 作者: spy
# 开发时间: 2021/12/13 16:32

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class BasePage:
    def __init__(self, driver):
        self.driver = driver

    def locator_element(self, loc):  # loc参数是一个元组
        """定位元素的关键字"""
        return self.driver.find_element(*loc)  # 加*解包，去掉一层()

    def set_keys(self, loc, value):
        """设置值的关键字"""
        self.locator_element(loc).send_keys(value)

    def click(self, loc):
        """单击的关键字"""
        self.locator_element(loc).click()

    def goto_frame(self, frame_name):
        """进入框架的关键字"""
        self.driver.switch_to.frame(frame_name)

    def quit_frame(self):
        """出框架的关键字"""
        self.driver.switch_to.default_content()

    def choice_select(self, loc, value):
        """  封装选中下拉框关键字"""
        sel = Select(self.locator_element(loc))
        sel.select_by_value(value)

    def get_value(self, loc):
        """获取文本的值"""
        return self.locator_element(loc).text
